package com.ruoyi.biz.imported.enums;

import cn.hutool.extra.spring.SpringUtil;
import com.ruoyi.biz.imported.strategy.*;
import com.ruoyi.common.exception.ServiceException;

/**
 * @author Fei.Cong
 * @date 2024-07-16 20:03
 */
public enum ImportedTemplateEnum {

    REGISTER("REGISTER", "省信访局地市级登记", CityRegisterStrategy.class),
    PROVINCE_REGISTER("PROVINCE_REGISTER", "省信访局厅本级登记", ProvinceRegisterStrategy.class),
    CLAIM("CLAIM", "认领", ClaimStrategy.class),
    DISPATCH("DISPATCH", "调度", DispatchStrategy.class),
    HOTLINE("HOTLINE", "热线", HotlineStrategy.class),
    MAILBOX("MAILBOX", "信箱", LeaderMailboxStrategy.class),
    VISIT("VISIT", "来访", VisitStrategy.class),
    TELEGRAM("TELEGRAM", "来电", TelegramStrategy.class),
    ;

    String type;
    String name;
    Class clazz;

    ImportedTemplateEnum(String type, String name, Class clazz) {
        this.type = type;
        this.name = name;
        this.clazz = clazz;
    }

    public String getType() {
        return type;
    }

    public String getName() {
        return name;
    }

    public Class getClazz() {
        return clazz;
    }

    public static ImportedTemplateEnum getType(String code) {
        for (ImportedTemplateEnum type : values()) {
            if (type.type.equals(code)) {
                return type;
            }
        }
        throw new ServiceException("未找到模板,请联系管理员");
    }

    public static ImportedStrategy getTemplateType(String type) {
        ImportedTemplateEnum[] values = ImportedTemplateEnum.values();
        for (ImportedTemplateEnum value : values) {
            if (value.getType().equals(type)) {
                return (ImportedStrategy) SpringUtil.getBean(value.getClazz());
            }
        }
        throw new ServiceException("未找到模板,请联系管理员");
    }
}
